// 记分牌类
class ScorePanel {
  // 默认值
  score = 0
  level = 1

  // 分数和等级所在元素属性
  scoreEle: HTMLElement
  levelEle: HTMLElement

  // 设置一个变量限制等级
  maxLevel: number
  // 设置每次升级的分数
  upScore: number

  constructor(maxLevel: number = 10, upScore: number = 10) {
    this.scoreEle = document.getElementById('score')!
    this.levelEle = document.getElementById('level')!
    this.maxLevel = maxLevel
    this.upScore = upScore
  }

  // 加分方法
  addScore() {
    // 分数自增
    this.scoreEle.innerText = ++this.score + ''
    // 判断分数是否升级
    if (this.score % this.upScore === 0) {
      this.addLevel()
    }
  }

  // 等级提升
  addLevel() {
    if (this.level < this.maxLevel) {
      this.levelEle.innerHTML = ++this.level + ''
    }
  }
}

// 测试代码
// const sp = new ScorePanel(100, 2)
// for (let i = 0; i < 200; i++) {
//   sp.addScore()
// }

export default ScorePanel
